/*
 * @Author: szx
 * @Date: 2021-12-04 10:51:54
 * @LastEditTime: 2021-12-04 11:02:42
 * @Description:
 * @FilePath: \leetcode\300-399\383\383.js
 */
/**
 * @param {string} ransomNote
 * @param {string} magazine
 * @return {boolean}
 */
var canConstruct = function (ransomNote, magazine) {
    const map = new Array(26).fill(0);
    const n = ransomNote.length;
    const m = magazine.length;
    if (n > m) return false;
    for (let i of magazine) {
        map[i.charCodeAt() - 97]++;
    }
    for (let i of ransomNote) {
        map[i.charCodeAt() - 97]--;
        if (map[i.charCodeAt() - 97] < 0) {
            return false;
        }
    }
    return true;
};
console.log(canConstruct('aa', 'ab'));
